package cn.jinbyte.data.changelog.filter;

import cn.jinbyte.data.changelog.annotation.ListLogProp;
import cn.jinbyte.data.changelog.annotation.EntityLogProp;
import cn.jinbyte.data.changelog.annotation.LogProp;

import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * 变更日志属性字段过滤器
 */
public class LogPropFieldFilter implements FieldFilter {

    private final String[] ignoreProps;

    public LogPropFieldFilter(String... ignoreProps) {
        this.ignoreProps = ignoreProps;
    }

    @Override
    public boolean condition(Field field) {
        if (field.getAnnotation(LogProp.class) != null
                || field.getAnnotation(EntityLogProp.class) != null
                || field.getAnnotation(ListLogProp.class) != null) {
            if (ignoreProps != null && ignoreProps.length > 0) {
                return Arrays.stream(ignoreProps).noneMatch(i -> i.equals(field.getName()));
            }
            return true;
        }
        return false;

    }
}
